package com.sunfeng.chap4.test41;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/11/9 15:08
 */
public class Client {
    public static void main(String[] args) {

        try {
            System.out.println("链接 begin " + System.currentTimeMillis());
            Socket socket = new Socket("127.0.0.1", 8088);
            System.out.println("链接 end " + System.currentTimeMillis());
            Thread.sleep(3000);
            char[] chars = new char[3];
            InputStream inputStream = socket.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            int readLength = inputStreamReader.read(chars);

            while (readLength != -1) {
                String string = new String(chars, 0, readLength);
                System.out.println(string);
                readLength = inputStreamReader.read(chars);
            }
            System.out.println();
            inputStreamReader.close();
            inputStream.close();

            socket.close();
            System.out.println("程序运行结束");
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }

    }
}
